<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>welcome</title>
</head>
<style>
  * {
    margin: 0;
    padding: 0;
  }

  html, body {
    width: 100%;
    height: 100%;
  }

  .welcome {
    padding: 30px 0;
    font-size: 30px;
    color: #757575;
    text-align: center;
    letter-spacing: 10px;
  }

  .input-wrap {
    padding: 0 10px 50px;
  }

  .input-elem {
    position: relative;
    padding-top: 20px;
    padding-bottom: 6px;
    margin-top: 20px;
  }

  .input-elem .input {
    position: relative;
    box-sizing: border-box;
    padding: 4px 0;
    font-size: 14px;
    width: 100%;
    z-index: 5;
    background: transparent;
    border: none;
    outline: none;
  }

  .input-elem .border {
    position: absolute;
    bottom: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 2px;
    background: #757575;
    z-index: 0;
  }

  .border:before {
    content: attr(data-placeholder);
    display: inline-block;
    font-size: 14px;
    color: #9E9E9E;
    transform: translateY(-30px);
    transition: all 200ms;
  }

  .border:after {
    content: '';
    display: inline-block;
    position: absolute;
    top: 0;
    left: 0;
    height: 2px;
    width: 0;
    background-image: linear-gradient(135deg, #5EFCE8 10%, #736EFE 100%);
    transition: all 200ms;
  }

  .check:before {
    color: #455A64;
    transform: translateY(-50px);
  }

  .check:after {
    width: 100%;
  }

  .button-wrap {
    padding: 0 10px;
  }

  .btn {
    width: 100%;
    height: 40px;
    font-size: 14px;
    letter-spacing: 5px;
    border: none;
    outline: none;
    border-radius: 4px;
    color: #ffffff;
    background-image: linear-gradient(135deg, #5EFCE8 10%, #736EFE 100%);
  }
</style>
<body>
<div class="main">
  <h1 class="welcome">WELCOME</h1>
  <div class="input-wrap">
    <div class="input-elem">
      <input class="input" type="text" data-key="gitPath">
      <span class="border" data-placeholder="Git命令地址"></span>
    </div>
    <div class="input-elem">
      <input class="input" type="text" data-key="gitUrl">
      <span class="border" data-placeholder="Git厂库地址"></span>
    </div>
    <div class="input-elem">
      <input class="input" id="dirPath" readonly type="text" data-key="gitDir">
      <span class="border" data-placeholder="本地厂库地址"></span>
    </div>
  </div>
  <div class="button-wrap">
    <button class="btn">确认</button>
  </div>
</div>
<script>window.$ = window.jQuery = require('jquery');</script>
<script src="./libs/layer/layer.js"></script>
<script>
  const {ipcRenderer} = require('electron');
  ipcRenderer.send('queryConfigData', {
    id: 'getConfigData'
  });
  ipcRenderer.on('getConfigData', function (event, args) {
    $('.input').each((i, item) => {
      const value = args[$(item).attr('data-key')];
      if (value) {
        $(item).val(value);
        $(item).next().addClass('check');
      }
    });
  });

  $('#dirPath').click(function () {
    ipcRenderer.send('chooseDir', {
      id: 'chooseDir'
    });
    ipcRenderer.on('getDirPath', (event, args) => {
      $(this).val(args);
      $(this).next().addClass('check');
    });
  });

  $('.input').focus(function () {
    $(this).next().addClass('check');
  });
  $('.input').blur(function () {
    if (!$(this).val()) {
      $(this).next().removeClass('check');
    }
  });
  $('.btn').click(function () {
    const obj = {};
    for (let i = 0; i < 3; i++) {
      const item = $($('.input')[i]);
      const value = item.val();
      if (!value) {
        const msg = '请输入' + item.next().attr('data-placeholder');
        layer.msg(msg, {icon: 5});
        return;
      } else {
        obj[item.attr('data-key')] = item.val();
      }
    }
    ipcRenderer.send('setConfig', {
      id: 'setConfig',
      data: obj
    });
    ipcRenderer.on('getUpdateStatus', function (event, args) {
      if (args) {
        layer.msg(args, {icon: 5});
      } else {
        layer.msg('配置更新成功,准备打开主界面', {icon: 1});
      }
    });
  });
</script>
</body>
</html>
